package petstore.web.servlet.space;

import petstore.domain.Log;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/logout")
public class LogoutServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        Log.getInstance().clear();
        HttpSession session = req.getSession();
        session.removeAttribute("lastTime");
        session.removeAttribute("isLogged");
        session.removeAttribute("uid");
        session.removeAttribute("username");
        session.removeAttribute("password");
        session.removeAttribute("orderItemList");
        resp.setHeader("refresh","0;URL = welcome");
    }
}
